<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('牛巡视记录列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>

                            圈舍号: <select name="roomNum" th:with="type=${@dict.getType('cow_juanshe_num')}">
                            <option value="">无</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            巡视人员：
                            <select id="createBy" name="createBy">
                                <option value="" selected="selected">无</option>
                                <option th:each="user:${users}" th:text="${user.loginName}"
                                        th:value="${user.loginName}"></option>
                            </select>
                        </li>

                        <li class="select-time">
                            <label>巡视时间： </label>
                            <input class="time-input" id="startTime" name="params[beginXunShiTime]" placeholder="开始时间"
                                   type="text"/>
                            <span>-</span>
                            <input class="time-input" id="endTime" name="params[endXunShiTime]" placeholder="结束时间"
                                   type="text"/>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary " onclick="openOrder()">
                <i class="fa fa-table"></i> 巡视记录单
            </a>
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncXunshiLogs:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncXunshiLogs:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncXunshiLogs:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 单据确认
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:ncXunshiLogs:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table data-mobile-responsive="true" id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncXunshiLogs:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncXunshiLogs:remove')}]];
    var prefix = ctx + "system/ncXunshiLogs/cow";

    $(function () {
        var options = {
            url: prefix + "/list/1/1",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "巡视记录",
            showExport: true,
            uniqueId : "xsId",
            columns: [{
                checkbox: true
            },
                {
                    field: 'xsId',
                    title: '巡视id',
                    visible: false
                },
                /*{
                    field : 'xsType',
                    title : '巡视类型 1:牛舍 2：鸡舍',
                    sortable: true
                },*/
                /*{
                    field : 'xsStatus',
                    title : '状态:1：待确认 2：已挂起 3：已确认：4：已生成订单',
                    sortable: true
                },*/
                /*{
                    field : 'orderId',
                    title : '订单id',
                    sortable: true
                },*/
                {
                    field: 'roomNum',
                    title: '圈舍号',
                    sortable: true
                },
                {
                    field: 'stockAmount',
                    title: '存栏数量',
                    sortable: true
                },
                {
                    field: 'xsAmount',
                    title: '巡视数量',
                    sortable: true
                },
                {
                    field: 'createBy',
                    title: '巡视人员',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '巡视时间',
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.xsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.xsId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*打开检测记录单*/
    function openOrder() {
        var url = ctx + 'system/ncOrder?orderType=16';
        $.modal.openTab("巡视牛舍记录单", url);
    }


    /*表单确认*/
    function confirmTable() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? selectFirstColumns() : selectColumns($.table._option.uniqueId);
        if (rows.length > 0) {
            $.modal.confirm("确认要发送请求?", function () {
                var url = prefix + "/confirmTable";
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        }
        else {
            var confirmTable = prefix + "/confirmTable";
            var data = $('#bootstrap-table').bootstrapTable('getData');
            if (data && data.length > 0) {
                $.modal.confirm("确认生成巡视单吗？", function () {
                    var ids = [];
                    $(data).each(function (i, e) {
                        ids.push(e.xsId);
                    });
                    var ids_str = ids.join(",");
                    myPost(confirmTable, {
                            ids: ids_str
                        },
                        function (data) {

                            if (data.code == 0) {
                                layer.msg("提交成功")
                            } else {
                                layer.msg(data.msg);
                            }
                            reload()
                        }, function (e) {
                            layer.msg("确认失败!");
                            reload()
                        })

                })
            } else {
                layer.msg("未发现数据!")
            }

        }
    }

    // 查询表格指定列值
    function selectColumns(column) {
        var rows = $.map($.btTable.bootstrapTable('getSelections'), function (row) {
            return row[column];
        });
        if ($.common.isNotEmpty($.table._option.rememberSelected) && $.table._option.rememberSelected) {
            rows = rows.concat(selectionIds);
        }
        return $.common.uniqueFn(rows);
    }

    // 查询表格首列值
    function selectFirstColumns() {
        var rows = $.map($.btTable.bootstrapTable('getSelections'), function (row) {
            return row[$.table._option.columns[1].field];
        });
        if ($.common.isNotEmpty($.table._option.rememberSelected) && $.table._option.rememberSelected) {
            rows = rows.concat(selectionIds);
        }
        return $.common.uniqueFn(rows);
    }

    //刷新页面
    function reload() {
        $.table.refresh();
    }

    setTitle("兽医管理-牛舍-巡视管理", true)
</script>
</body>
</html>